version 14.2
#delimit ;
log using "F:\Government Formation in Asian-Pacific Democracies.log", replace;
set more off;


* ***************************************************************** *;
* ***************************************************************** *;
* File-Name: model2_pp_f1_1_parl.do *;
* Date: 5/30/2022 *;
* Author: MG *;
* Purpose: Marginal effect plot [Coalition Clusters](Parliamentary Formateur: Legislature Power) *;
* Input File: data_stata_pp.dta *;
* Data Output: None *;
* Previous file: None *;
* Machine: laptop *;
* **************************************************************** *;
* **************************************************************** *;

use "F:\Government Formation in Asian-Pacific Democracies\Portfolio Allocation\data_stata_pp.dta", clear;


gen portfolioshare = . ;

replace portfolioshare = party_port2/gov_port2 ;

gen seatshare = . ;

replace seatshare = party_seats/gov_seats ;

gen parliamentary = . ;
 
replace parliamentary = 1 if presidential ==0 ;

replace parliamentary = 0 if presidential == 1 ;

gen seatshare_parl = . ;

replace seatshare_parl = seatshare * parliamentary ;

gen formateur_parl = . ;

replace formateur_parl = formateur * parliamentary ;

gen seat_legpower = . ;

replace seat_legpower = seatshare * legpower ;

gen legpower_parl = . ;

replace legpower_parl = legpower * parliamentary ;

gen formateur_legpower = . ;

replace formateur_legpower = formateur * legpower ;

gen form_legpower_parl = . ;

replace form_legpower_parl = formateur * legpower * parliamentary ;

gen seat_legpower_parl = . ;

replace seat_legpower_parl = seatshare * legpower * parliamentary ;

************************* ;
*  Summarize variables    ;
************************* ;

sum;


********************************************************************** ;
*  Table 1, Model 2, re-arranged to put seatshare IVs last           ;
* Y = b0 + b1X + b2W + b3Z + b4XW + b5XZ + b6WZ * b7XZW + controls + e ;
*    formateur is X, parliamentary is W, legpower is Z                 ;
* formateur_parl is XW, formateur_legpower is XZ, legpower_parl is WZ, ; 
* form_legpower_parl is XWZ, then control variables                    ; 
********************************************************************** ;

regress portfolioshare formateur parliamentary legpower 
formateur_parl formateur_legpower legpower_parl 
form_legpower_parl 
seatshare seatshare_parl seat_legpower seat_legpower_parl, cluster(cabinetcode) ;

**************************************************************** ;
*  grab the elements of the estimated coefficient vector and     ;
*  the variance-covariance matrix                                ;
**************************************************************** ;

matrix b=e(b);
matrix V=e(V);

scalar b1=b[1,1];
scalar b2=b[1,2];
scalar b3=b[1,3];
scalar b4=b[1,4];
scalar b5=b[1,5];
scalar b6=b[1,6];
scalar b7=b[1,7];

scalar varb1=V[1,1];
scalar varb2=V[2,2];
scalar varb3=V[3,3];
scalar varb4=V[4,4];
scalar varb5=V[5,5];
scalar varb6=V[6,6];
scalar varb7=V[7,7];
scalar covb1b4=V[1,4]; 
scalar covb1b5=V[1,5];
scalar covb1b7=V[1,7]; 
scalar covb4b5=V[4,5]; 
scalar covb4b7=V[4,7]; 
scalar covb5b7=V[5,7];


scalar list b1 b2 b3 b4 b5 b6 b7 varb1 varb2 varb3 varb4 varb5 varb6 varb7 covb1b4 covb1b5 covb1b7 covb4b5 covb4b7 covb5b7;

estat vce;

* **************************************************************** *;
*     Calculate data necessary for  marginal effect plot           *;
*       Create values for horizontal axis                          *;
* **************************************************************** *;

set obs 1000;

gen MVZ = (_n-1)/1000;

replace MVZ=. if _n>1000;


* **************************************************************** *;
* We want to calculate the marginal effect of X (formateur) on     *;
* Y (portfolioshare) for all values of the modifying variable Z    *;
* (legpower). We want to calculate this marginal effect when Z     *;
* changes for a specific value of the second modifying variable W  *;
* (parliamentary), when W = 1 (parliamentary regimes)               *;
* **************************************************************** *;

gen marginal_formateur = b1+b4+b5*MVZ+b7*MVZ;

gen se_formateur = sqrt(varb1+varb4+varb5*(MVZ^2)+varb7*(MVZ^2)
+2*covb1b4+2*MVZ*covb1b5)*2*MVZ*covb1b7+2*MVZ*covb4b5 
+2*MVZ*covb4b7+2*(MVZ^2)*covb5b7 ;

gen bound = 1.96*se_formateur;

gen upper = marginal_formateur+bound;

gen lower = marginal_formateur-bound;

gen yline=0;

*gen conb0=b1+b4*0+b5*MVZ+b7*(0*MVZ) if _n<100;



*     ****************************************************************  *;
*     Produce Figure A.1(a): Effect of Formateur on Portfolioshare      *;
*     over a range of Legislative Power values for parliamentary cases  *;
*     ****************************************************************  *;

graph twoway hist legpower if parliamentary==1 & legpower<1, width(0.04) percent color(gs15) yaxis(2)
    || line marginal_formateur MVZ if MVZ<1 & MVZ>0, clpattern(solid) clwidth(medthick) clcolor(black) yaxis(1)
    || line lower MVZ if MVZ<1 & MVZ>0, clpattern(dash) clwidth(thin) clcolor(red)
    || line upper MVZ if MVZ<1 & MVZ>0, clpattern(dash) clwidth(thin) clcolor(red)
    || line yline MVZ, clpattern(solid) clwidth(thin) clcolor(black)
    ||,
    xlabel(0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0, nogrid labsize(2.5))
    ylabel(-1.0 -0.75 -0.5 -0.25 0 0.25 0.5 0.75 1 1.25 1.5 1.75 2, axis(1) nogrid labsize(2.5))
    ylabel(0 10 20 30 40 50, axis(2) nogrid labsize(2.5) labcolor(gs12) tlcolor(gs12))
        yscale(noline alt)
        yscale(noline alt axis(2))
        xscale(noline)
        legend(off)
        title("{stSerif:(a) Legislature Power and Formateur Bonus}",  size(3.5))
        xtitle("{stSerif:Legislative Power}",  size(3) height(7) )
        ytitle("{stSerif:Percentage of Observations}", color(gs12) axis(2) size(3) margin(5 0 0 0))
        ytitle("{stSerif:Marginal Effect of Formateur}", size(3) height(7)) 
        scheme(s2mono) graphregion(fcolor(white) ilcolor(white) lcolor(white)); 

      
graph export "F:\Government Formation in Asian-Pacific Democracies\Portfolio Allocation\model4_parl.wmf", replace;  
 
 
log close;
exit;

